//
// Created on 2022/6/8.
//

#ifndef ijkplayer_napi_utils_H
#define ijkplayer_napi_utils_H
#include <string>
#include <napi/native_api.h>
#include "native_common.h"
#include "native_node_api.h"

class NapiUtil {
public:
    static void JsValueToString(const napi_env &env, const napi_value &value, const int32_t bufLen,
        std::string &target);
    static void JsObjectToString(const napi_env &env, const napi_value &object, std::string fieldStr,
        const int32_t bufLen, std::string &fieldRef);
    static bool JsObjectGetProperty(const napi_env &env, const napi_value &object, std::string fieldStr,
        napi_value &value);
    static void JsObjectToInt(const napi_env &env, const napi_value &object, std::string fieldStr, int32_t &fieldRef);
    static bool JsUint8ArrayParse(const napi_env &env, const napi_value &object, uint8_t **uint8Buffer,
        size_t &bufferSize, size_t &offset);
    static void Uint8ArrayToJsValue(const napi_env &env, std::vector<uint8_t> &uint8Buffer, size_t bufferSize,
        napi_value &result);
    static void SetValueUtf8String(const napi_env &env, std::string fieldStr, std::string str, napi_value &result);
    static void SetValueInt32(const napi_env &env, std::string fieldStr, const int32_t intValue, napi_value &result);
    static void SetValueBool(const napi_env &env, std::string fieldStr, const bool boolValue, napi_value &result);
    static napi_value SetNapiCallBool(const napi_env env, bool value);
};


#endif //ijkplayer_napi_utils_H
